from google.appengine.ext import db
from google.appengine.api import users

# Data Models
class Sequence(db.Model):
  url_id = db.IntegerProperty()

class Banner(db.Model):
  name = db.StringProperty()
  expires = db.DateProperty()
  ad_code = db.TextProperty()
  rand = db.FloatProperty()

class Url(db.Model):
  url = db.StringProperty()
  url_id = db.IntegerProperty()
  slug = db.StringProperty() # self.key().id()
  created = db.DateTimeProperty(auto_now_add=True)
  accessed = db.DateTimeProperty(auto_now=True)
  clean_url = db.StringProperty()
  counter = db.IntegerProperty(default=0)
  domain_counter = db.IntegerProperty(default=0)
  page_title = db.StringProperty()
  twitter_users = db.StringListProperty(default=None)
  users = db.StringListProperty(default=None)
  first_ip_addr = db.StringProperty()

class Tweet(db.Model):
  slug              = db.StringProperty()
  twitter_user      = db.StringProperty()
  tweet             = db.StringProperty()
  tweet_id          = db.StringProperty()
  profile_image_url = db.StringProperty()
  created_at        = db.DateTimeProperty()

class ReferrerDomain(db.Model):
  url_id = db.IntegerProperty()
  domain = db.StringProperty()
  counter = db.IntegerProperty(default=0)
  last_click = db.DateTimeProperty(auto_now=True)

class Referrer(db.Model):
  url_id = db.IntegerProperty()
  domain_id = db.IntegerProperty()
  referrer = db.StringProperty()
  counter = db.IntegerProperty(default=0)

class Click(db.Model):
  url_id = db.IntegerProperty()
  referrer_id = db.IntegerProperty()
  timestamp = db.DateTimeProperty(auto_now=True)

class TwitterUser(db.Model):
  twitter_user = db.StringProperty()
  url_counter = db.IntegerProperty(default=0)
  created = db.DateTimeProperty(auto_now_add=True)

class Settings(db.Model):
	user = db.UserProperty()
	twitter_accts = db.StringListProperty(default=None)
	important_domains = db.StringListProperty(default=None)	

class UserTwitterAccts(db.Model):
	user = db.UserProperty()
	twitter_acct = db.StringProperty()
	twitter_password = db.StringProperty()
